﻿using System.Runtime.InteropServices;

namespace EFObjectContextScope
{
    [StructLayout(LayoutKind.Sequential)]
    internal struct ObjectContextTraceIdentifier
    {
        public static readonly ObjectContextTraceIdentifier Empty;
        private string contextIdentifier;
        private int cloneIdentifier;

        public ObjectContextTraceIdentifier(string contextIdentifier, int cloneIdentifier)
        {
            this.contextIdentifier = contextIdentifier;
            this.cloneIdentifier = cloneIdentifier;
        }

        public string ObjectContextWrapperIdentifier
        {
            get
            {
                return this.contextIdentifier;
            }
        }
        public int CloneIdentifier
        {
            get
            {
                return this.cloneIdentifier;
            }
        }
        public override int GetHashCode()
        {
            return base.GetHashCode();
        }

        public override bool Equals(object objectToCompare)
        {
            if (!(objectToCompare is ObjectContextTraceIdentifier))
            {
                return false;
            }
            ObjectContextTraceIdentifier identifier = (ObjectContextTraceIdentifier)objectToCompare;
            return (!(identifier.ObjectContextWrapperIdentifier != this.ObjectContextWrapperIdentifier) && (identifier.CloneIdentifier == this.CloneIdentifier));
        }

        public static bool operator ==(ObjectContextTraceIdentifier id1, ObjectContextTraceIdentifier id2)
        {
            return id1.Equals(id2);
        }

        public static bool operator !=(ObjectContextTraceIdentifier id1, ObjectContextTraceIdentifier id2)
        {
            return !id1.Equals(id2);
        }

        static ObjectContextTraceIdentifier()
        {
            Empty = new ObjectContextTraceIdentifier();
        }

    }
}
